<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");

      this.chart.setOption({
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
            label: false,
          },
          showContent: false,
        },
        grid: {
          x: 65,
          y: 25,
          x2: 10,
          y2: 30,
          borderWidth: 1,
        },
        xAxis: {
          type: "category",
          data: [
            "叉车",
            "拖车",
            "挖掘机",
            "渣土车",
            "挖掘机",
            "挖掘机",
            "挖掘机",
            "挖掘机",
          ],
          axisLabel: {
            color: "black",
          },
          axisTick: {
            alignWithLabel: true,
          },
        },
        yAxis: {
          type: "value",
          splitLine: {
            show: true,
            lineStyle: {
              type: "dashed",
            },
          },
        },
        series: [
          {
            data: [1000, 200, 150, 80, 700, 110, 1300, 2500],
            type: "bar",
            // showBackground: true,
            backgroundStyle: {
              // color: 'rgba(180, 180, 180, 0.1)',//描边颜色
              // borderWidth:30,//阴影部分的宽度  不生效
            },
            itemStyle: {
              color: "#307ff9",
              opacity: 0.9,
            },
            emphasis: {
              //选中的样式
              focus: "series",
              label: {
                show: true,
                position: "top",
                color: "blue",
                fontStyle: "oblique",
                fontWeight: "bolder",
                fontSize: "20",
                fontFamily: "myFirstFont",
              },
            },
            selectedMode: true,
            barWidth: 14,
            showBackground: false, //
            markLine: {
              lineStyle: {
                color: "red",
              },
            },
          },
        ],
      });
    },
  },
};
</script>
